package com.shop.config;

import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * @author XCH
 * @date 2025/5/19
 */
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[0];
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{RootConfig.class};
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        //参数1：文件夹路径
        //参数2：单个文件的大小（单位：字节）
        //参数3：总上传数据大小
        //参数4：单个文件达到指定大小后将写成文件
        MultipartConfigElement multipartConfigElement = new MultipartConfigElement("",  20971520, 2097152000, 20971520);
        registration.setMultipartConfig(multipartConfigElement);
        registration.setLoadOnStartup(0);

    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}